package cn.qidisoft.edu.hzjt.service.zyc.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.zyc.PartyNoticeMapper;
import cn.qidisoft.edu.hzjt.model.zyc.PartyNotice;
import cn.qidisoft.edu.hzjt.model.zyc.ScientificNotice;
import cn.qidisoft.edu.hzjt.service.zyc.IPartyNoticeService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 管理公示公告 Service 实现层
 * @author zhangwenliang
 *@Date 2018.12.15
 */
@Service
public class PartyNoticeServiceImpl implements IPartyNoticeService{
    
	  protected static final LoggerAdapter LOGGER = LoggerAdapterFactory
	            .getLogger(LogType.HZJT_LOGGER.val);

    @Autowired
    private PartyNoticeMapper partyNoticeMapper;
	
	@Override
	public PaginationBean<PartyNotice> getListData(Map<String, Object> queryMap, Page page) {
		 try {
	            int c = partyNoticeMapper.queryPageListcount(queryMap);
	            int totalRecords = c;
	            PaginationBean<PartyNotice> pageHolder = new PaginationBean<>(page, totalRecords);
	            List<PartyNotice> resultList = partyNoticeMapper
	                    .queryPageList(queryMap,
	                            new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
	                                    pageHolder.getPageSize()));
	            pageHolder.setPageList(resultList);
	            return pageHolder;
	        } catch (Exception e) {
	            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
	                    this.getClass().getName(),
	                    ToStringBuilder.reflectionToString(queryMap, ToStringStyle.SHORT_PREFIX_STYLE));
	            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
	                    e);
	        }
	}

	@Override
	public Integer insert(PartyNotice partyNotice) {
		
		return partyNoticeMapper.insert(partyNotice);
	}

	@Override
	public PartyNotice getPartyNotice(PartyNotice partyNotice) {
		
		return partyNoticeMapper.getPartyNotice(partyNotice);
	}

	@Override
	public Integer update(PartyNotice partyNotice) {
		
		return partyNoticeMapper.update(partyNotice);
	}

	@Override
	public void delete(PartyNotice partyNotice) {
		try {
			partyNoticeMapper.delete(partyNotice);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(partyNotice, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
	}

	@Override
	public List<PartyNotice> getPartyNoticeList(Map<String, Object> queryMap) {
		return partyNoticeMapper.getPartyNoticeList(queryMap);
	}

	public List<PartyNotice> getpartyNoticeEight() {
		
		return partyNoticeMapper.getpartyNoticeEight();
	}

	@Override
	public PartyNotice getByGgId(Integer gGid) {
		
		return partyNoticeMapper.getByGgId(gGid);
	}

}
